﻿using System.Runtime.InteropServices;

namespace MultipleThread
{
    internal class Program
    {
        static void ThreadTest()
        {
            // 创建并启动多个线程
            var threads = new System.Threading.Thread[5];
            for (int i = 0; i < threads.Length; i++)
            {
                int threadIndex = i; // 捕获当前的索引值
                threads[i] = new System.Threading.Thread(() =>
                {
                    Console.WriteLine($"Thread {threadIndex} is running.");
                    System.Threading.Thread.Sleep(1000); // 模拟工作
                    Console.WriteLine($"Thread {threadIndex} has finished.");
                });
                threads[i].Start();
            }
            // 等待所有线程完成
            foreach (var thread in threads)
            {
                thread.Join();
            }
        }
        static void TaskTest()
        {
            // 创建并启动多个任务
            var tasks = new System.Threading.Tasks.Task[5];
            for (int i = 0; i < tasks.Length; i++)
            {
                int taskIndex = i; // 捕获当前的索引值
                tasks[i] = System.Threading.Tasks.Task.Run(() =>
                {
                    Console.WriteLine($"Task {taskIndex} is running.");
                    System.Threading.Thread.Sleep(1000); // 模拟工作
                    Console.WriteLine($"Task {taskIndex} has finished.");
                });
            }
            // 等待所有任务完成
            System.Threading.Tasks.Task.WaitAll(tasks);
        }

        //定义一个Dll import
        [DllImport("*")]
        internal static extern void SetIcsNativeaotActiveCode(byte[] activeCode);
        static void Main(string[] args)
        {
            var activeCode = new byte[] { 0x3B, 0xD9, 0xDD, 0xF5, 0x00, 0xCE, 0x42, 0x8D, 0x5D, 0xAA, 0xEA, 0x90, 0x81, 0xB8, 0xEE, 0x80, 0xAB, 0xCD, 0x78, 0x71, 0xA3, 0xB1, 0x97, 0x4F, 0x9C, 0x01, 0xCE, 0xE2, 0x58, 0x0A, 0x84, 0xB1, };
            //获取当前platform
            var platform = RuntimeInformation.ProcessArchitecture;
            if (platform == Architecture.Arm)
            {
                SetIcsNativeaotActiveCode(activeCode);
            }
            ThreadTest();
            TaskTest();
            Console.WriteLine("Test Complete!");
        }
    }
}
